package com.jsgt.greekfire.repository

import com.jsgt.greekfire.bean.*
import com.jsgt.greekfire.common.http.ResponseData
import com.jsgt.greekfire.common.http.ResultData
import com.jsgt.greekfire.common.http.RetrofitManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.MediaType
import okhttp3.RequestBody
import retrofit2.http.Query

/**
 * author fhx
 * create time 2020/4/25 20:55
 **/
class UserRepository : BaseRepository() {
    companion object {
        val instance = UserRepository()
    }

    /**
     * 获取地址信息
     */
    suspend fun getAccount(params: Map<String, Any>): AtrAccountInfoBean =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.getaccount(parseBody(params))
        }

    /**
     * 创建一笔转账Transaction
     */
    suspend fun transfer(params: String): TransferResult =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.transfer(RequestBody.create(MediaType.get("application/json; charset=UTF-8"),params))
        }

    /**
     * 交易列表
     */
    suspend fun getTradeOrderList(address: String, contractType: String?, start: String, limit: String): TradeOrderPage =
        withContext(Dispatchers.IO) {
            RetrofitManager.createBlockService().getTradeOrderList(address,contractType,start,limit)
        }

    /**
     * 获取版本更新
     */
    suspend fun getVersion(): ResponseData<Version> =
        withContext(Dispatchers.IO) {
            RetrofitManager.createServerService().getVersion()
        }
  //-----------------------------------------------以上ATR--------------------------------------------------------
    /**
     * 用户信息
     */
    suspend fun userInfo(): ResponseData<UserBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.userInfo()
        }

    /**
     * 最新公告
     */
    suspend fun noticeList(params:  Map<String, Any>): ResponseData<MessagePage> =
        withContext(Dispatchers.IO) {
            RetrofitManager.createServerService().noticeList(parseBody(params))
        }

    /**
     * 消息列表
     */
    suspend fun messageList(): ResponseData<List<MessageBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.messageList()
        }

    /**
     * 消息详情
     */
    suspend fun messageInfo(): ResponseData<MessageBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.messageInfo()
        }

    /**
     * 发送短信
     */
    suspend fun sendSMS(phoneNumber: String, key: String): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.sendSMS(phoneNumber, key)
        }

    /**
     * 矿池活动是否开启
     */
    suspend fun poolActiveIsStart():ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.poolActiveIsStart()
        }

    /**
     * 创世区块是否开启
     */
    suspend fun genesisActiveIsStart():ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.genesisActiveIsStart()
        }


    /**
     * 发送邮箱
     */
    suspend fun sendEmail(email: String, key: String): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.sendEmail(email, key)
        }

    /**
     * 验证短信码
     */
    suspend fun checkSMSCode(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.checkSMSCode(parseBody(params))
        }

    /**
     * 验证邮箱
     */
    suspend fun checkEmailCode(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.checkEmailCode(parseBody(params))
        }

    /**
     * 修改交易密码
     */
    suspend fun updateTradingPwd(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.updateTradingPwd(parseBody(params))
        }

    /**
     * 修改安全密码
     */
    suspend fun updateSecurityPwd(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.updateSecurityPwd(parseBody(params))
        }

    /**
     * 计价货币列表
     */
    suspend fun valuationCoinList(): ResponseData<List<Any>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.valuationCoinList()
        }

    /**
     * 修改计价货币
     */
    suspend fun updateValuationCoin(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.updateValuationCoin(parseBody(params))
        }

    /**
     * 绑定手机
     */
    suspend fun bindPhone(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.bindPhone(parseBody(params))
        }

    /**
     * 修改手机
     */
    suspend fun modifyPhone(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.modifyPhone(parseBody(params))
        }

    /**
     * 绑定邮箱
     */
    suspend fun bindEmail(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.bindEmail(parseBody(params))
        }

    /**
     * 修改邮箱
     */
    suspend fun editEmail(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.editEmail(parseBody(params))
        }

    /**
     * 转账激活
     */
    suspend fun activityTransfer(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.activityTransfer(parseBody(params))
        }

    /**
     * 确定激活
     */
    suspend fun activityTransfer2(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.activityTransfer2(parseBody(params))
        }

    /**
     * 确定激活列表
     */
    suspend fun activityTransferList(): ResponseData<List<TransferBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.activityTransferList()
        }

    /**
     * 查询币种价格
     */
    suspend fun getPrice(): ResponseData<GetPrice> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.getPrice()
        }

    /**
     * 查询持币
     */
    suspend fun myCoinNumber(): ResponseData<MinerBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.myCoinNumber()
        }

    /**
     * 全网总产出
     */
    suspend fun totalCoinNumber(): ResponseData<String> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.totalCoinNumber()
        }

    /**
     * 矿池列表
     */
    suspend fun coinPoolList(params: Map<String, Any>): ResponseData<ResultData<MinerBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.coinPoolList(parseBody(params))
        }

    /**
     * 地址簿列表
     */
    suspend fun addressList(params: Map<String, Any>): ResponseData<List<AddressBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.addressList(parseBody(params))
        }

    /**
     * 添加地址
     */
    suspend fun addAddress(params: Map<String, Any>): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.addAddress(parseBody(params))
        }

    /**
     * 个人钱包地址
     */
    suspend fun walletAddress(guid: String): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.walletAddress(guid)
        }

    /**
     * 标记详情
     */
    suspend fun markDetail(assetId: String): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.markDetail(assetId)
        }

    /**
     * 币币账单列表
     */
    suspend fun assetsLogList(params: Map<String, Any>): ResponseData<List<BillBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.assetsLogList(parseBody(params))
        }
    /**
     * 币币账单列表
     */
    suspend fun rechargeLogList(params: Map<String, Any>): ResponseData<List<BillBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.rechargeLogList(parseBody(params))
        }
    /**
     * 提币记录
     */
    suspend fun withdrawRecord(params: Map<String, Any>): ResponseData<ResultData<BillBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.withdrawRecord(parseBody(params))
        }


    /**
     * 资产列表
     */
    suspend fun userAssetList(): ResponseData<List<AssetsBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.userAssetList()
        }

    /**
     * 资产管理列表
     */
    suspend fun userAssetManageList(): ResponseData<List<AssetsBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.userAssetManageList()
        }

    /**
     * 矿池列表
     */
    suspend fun poolData(): ResponseData<IncomeBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.poolData()
        }

    /**
     * 版本更新
     */
    suspend fun getAppVersion(): ResponseData<UpdateBean> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.getAppVersion()
        }

    /**
     * 版本更新
     */
    suspend fun logout(): ResponseData<Any> =
        withContext(Dispatchers.IO) {
            RetrofitManager.userService.logout()
        }
}